/************************************************************************
 * AIDE - Automata Identification Engine
 * Copyright (C) 2012-2013 Ali Khalili (khalili_DOT_ir_@SIGN_gmail_DOT_com)
 * **********************************************************************
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License (LGPL) published 
 * by the Free Software Foundation; either version 2.1 of the License, or (at your
 * option) any later version. This program is distributed without any
 * warranty. See the GNU Lesser General Public License for more details. 
 * ***********************************************************************
 * File         :     
 * Description  :     
 * Change log   :     	-Date:  Change
 ************************************************************************/
using System;

namespace SMLib.Automata.Base
{
	/// <summary>
	/// symbol of N bits
	/// </summary>
	public class NbitSymbol :ISymbol
	{
		bool[] bits;

		public NbitSymbol (int n)
		{
			bits = new bool[n];
		}

		public NbitSymbol (bool[] bits)
		{
			this.bits = new bool[bits.Length];
			for (int i=0; i<bits.Length; i++)
				this.bits [i] = bits [i];
		}

		public NbitSymbol (string bits)
		{
			this.bits = new bool[bits.Length];
			for (int i=0; i<bits.Length; i++)
				if (bits [i] == '0')
					this.bits [i] = false;
				else if (bits [i] == '1')
					this.bits [i] = true;
				else
					throw new Exception ();
		}

		/// <summary>
		/// Gets the length of symbol (i.e. number of bits)
		/// </summary>
		/// <value>The length.</value>
		public int Length {
			get {
				return bits.Length;
			}
		}

		public override bool Equals (object obj)
		{
			if (!(obj is NbitSymbol))
				return false;
			NbitSymbol obj2 = (NbitSymbol)obj;
			if (obj2.bits.Length != bits.Length)
				return false;
			for (int i=0; i<bits.Length; i++)
				if (bits [i] != obj2.bits [i])
					return false;
			return true;
		}

		public override string ToString ()
		{
			string str = "";
			for (int i=0; i<bits.Length; i++)
				str += (bits [i] ? '1' : '0');
			return str;
		}

		public override int GetHashCode ()
		{
			return base.GetHashCode ();
		}
		#region ISymbol implementation
		public Type TypeOfSymbol ()
		{
			return typeof(NbitSymbol);
		}

		public object ContentObject {
			get {
				return bits;
			}
			set {
				throw new NotImplementedException ();
			}
		}
		#endregion
	}
}

